package com.nf.health.app.adapter;

import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.models.SchemeVo;
import com.nf.health.app.utils.ImageLoaderUtils;
import com.nf.health.app.utils.Util;

import java.util.List;

/**
 * Created by Administrator on 2016/3/22.
 */
public class SchemeAdapter extends BaseAdapter{
    List<SchemeVo> newsList;
    Activity activity;
    LayoutInflater inflater = null;
    public SchemeAdapter(Activity activity, List<SchemeVo> newsList) {
        this.activity = activity;
        this.newsList = newsList;
        inflater = LayoutInflater.from(activity);
    }
    @Override
    public int getCount() {
        return newsList == null ? 0 : newsList.size();
    }

    @Override
    public Object getItem(int position) {
        if (newsList != null && newsList.size() != 0) {
            return newsList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SchemeVo item = newsList.get(position);


        ViewHolder holder;

        int a = Integer.parseInt(item.getDaynum());
        int b = Integer.parseInt(item.getTotaldaynum());

        int c = a*100/b;


        if(c==100){
            holder = ViewHolder.get(parent, convertView, R.layout.item_scheme2, position);
            holder.setText(R.id.tv_tempo, "完成");
//            Long time = Long.parseLong();
            String result = Util.timeStamp2Date(item.getEndtime(), "");
            if(TextUtils.isEmpty(result)){
            }else{
                String bbb[] = result.split(" ");
                holder.setText(R.id.scheme_time,bbb[0]);
            }
            ImageView iv_user_head_icon = holder.getView(R.id.scheme_image);
            ImageLoaderUtils.getinstance(activity).getImage(iv_user_head_icon, item.getImgurl(), R.drawable.default_image);

            holder.setText(R.id.tv_name, item.getName());
            if(TextUtils.isEmpty(item.getDoctorsource())){
                holder.setText(R.id.tv_var,"来源："+"系统");
            }else{
                holder.setText(R.id.tv_var,"来源："+item.getDoctorsource());
            }
        }else{
            holder = ViewHolder.get(parent, convertView, R.layout.item_scheme, position);
            holder.setText(R.id.tv_tempo,"完成"+c+"%");
            ImageView iv_user_head_icon = holder.getView(R.id.scheme_image);
            ImageLoaderUtils.getinstance(activity).getImage(iv_user_head_icon, item.getImgurl(), R.drawable.default_image);

            holder.setText(R.id.tv_name, item.getName());
            if(TextUtils.isEmpty(item.getDoctorsource())){
                holder.setText(R.id.tv_var,"来源："+"系统");
            }else{
                holder.setText(R.id.tv_var,"来源："+item.getDoctorsource());
            }
        }




        return holder.getConvertView();
    }
}
